<html>
<head><meta charset="utf-8"><title>More coercions from fn item -&gt; fn pointer · t-lang · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/index.html">t-lang</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html">More coercions from fn item -&gt; fn pointer</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="199913775"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/199913775" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nikhil Benesch <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#199913775">(Jun 05 2020 at 18:08)</a>:</h4>
<p><span aria-label="wave" class="emoji emoji-1f44b" role="img" title="wave">:wave:</span> Hi lang team. I just got bitten by the fact that generic parameters won't coerce function items to function pointers. This is described pretty fully in this issue: <a href="https://github.com/rust-lang/rust/issues/62385">https://github.com/rust-lang/rust/issues/62385</a>. </p>
<p>The discussion there is mostly about improving the diagnostic, but it seems to me like a better fix would be to actually provide this coercion. I'd be happy to try to write up an RFC for that if that seems like a reasonable thing to do?</p>



<a name="199921865"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/199921865" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#199921865">(Jun 05 2020 at 19:15)</a>:</h4>
<p>The problem is more of an implementation challenge</p>



<a name="199921888"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/199921888" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#199921888">(Jun 05 2020 at 19:15)</a>:</h4>
<p>It's connected to the system we use for coercions</p>



<a name="199921908"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/199921908" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#199921908">(Jun 05 2020 at 19:16)</a>:</h4>
<p>and it would not be all that easy to fix</p>



<a name="199921990"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/199921990" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#199921990">(Jun 05 2020 at 19:16)</a>:</h4>
<p>so I don't think an RFC is really the required step</p>



<a name="199922015"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/199922015" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#199922015">(Jun 05 2020 at 19:16)</a>:</h4>
<p>I don't really see any short-term fix to be honest, though I have some longer term thoughts</p>



<a name="199924290"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/199924290" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nikhil Benesch <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#199924290">(Jun 05 2020 at 19:38)</a>:</h4>
<p>Glad I asked. I'm going to forward that sentiment to a comment on the issue unless you'd like to do so yourself <span class="user-mention" data-user-id="116009">@nikomatsakis</span>?</p>



<a name="199926721"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/199926721" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#199926721">(Jun 05 2020 at 19:58)</a>:</h4>
<p>nope feel free ;)</p>



<a name="199942353"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/199942353" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nikhil Benesch <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#199942353">(Jun 05 2020 at 22:48)</a>:</h4>
<p>Is there more up to date status on <a href="https://github.com/rust-lang/rust/issues/62530">https://github.com/rust-lang/rust/issues/62530</a> anywhere? (It seems like that is the underlying issue at least?)</p>



<a name="203814532"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/203814532" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#203814532">(Jul 14 2020 at 09:37)</a>:</h4>
<p>I am also getting bitten by this, as I'm working on a kernel mostly in rust, and I'm using a type erased array to store pointers to syscall functions.<br>
Naturally, of course, I can't typecheck these functions for sanity without spending half the source file on macros to force an fn-item -&gt; fn-pointer coercions (I don't want to have to repeat the signature rust should know all about anyways).</p>



<a name="203888489"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/203888489" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#203888489">(Jul 14 2020 at 21:08)</a>:</h4>
<p><span class="user-mention" data-user-id="257758">@Connor Horman</span> but you don't need to specify the signature, just <code>as fn(_, _) -&gt; _</code> should be enough</p>



<a name="203889257"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/203889257" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#203889257">(Jul 14 2020 at 21:14)</a>:</h4>
<p>also, what does "type-erased" look like in this case?</p>



<a name="203889319"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/203889319" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#203889319">(Jul 14 2020 at 21:15)</a>:</h4>
<p>there may be an easy way to make it all fit (also, most macros should be tiny for stuff like this I'd expect)</p>



<a name="203912454"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/203912454" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#203912454">(Jul 15 2020 at 03:04)</a>:</h4>
<p>fn(_, _)-&gt; _ would work for 2 parameter syscalls</p>



<a name="203912476"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/203912476" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#203912476">(Jul 15 2020 at 03:05)</a>:</h4>
<p>I'm erasing 0 to 6 parameter unsafe extern"C" functions with only specific types down to a Sync wrapper arround a *const ()</p>



<a name="203913202"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/203913202" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#203913202">(Jul 15 2020 at 03:25)</a>:</h4>
<p>what I meant is that you only need to account for arity, not the actual types</p>



<a name="203913207"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/203913207" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#203913207">(Jul 15 2020 at 03:25)</a>:</h4>
<p><span class="user-mention" data-user-id="257758">@Connor Horman</span> wait doesn't <code>as *const ()</code> "just work"?</p>



<a name="203913212"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/203913212" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#203913212">(Jul 15 2020 at 03:25)</a>:</h4>
<p>or maybe <code>as usize</code></p>



<a name="203913508"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/203913508" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#203913508">(Jul 15 2020 at 03:33)</a>:</h4>
<p><code>as usize</code> should work for any fn type, yeah</p>



<a name="203946685"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/203946685" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#203946685">(Jul 15 2020 at 12:11)</a>:</h4>
<p>The arity is the hard part. <code>as *const ()</code> would certainly work, however I want to typecheck the signature to make sure:</p>
<ul>
<li>Its extern"C"</li>
<li>Its unsafe (doesn't necessarily need to check this, but I can live with adding unsafe to all my syscall functions</li>
<li>Each parameter is either a primitive Integer, a special transparent wrapper arround a primitive integer, or a pointer in the calling process' paged memory. </li>
<li>Each return type is also one of those.</li>
</ul>



<a name="203946707"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/203946707" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#203946707">(Jul 15 2020 at 12:11)</a>:</h4>
<p>hmm</p>



<a name="203946738"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/203946738" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#203946738">(Jul 15 2020 at 12:11)</a>:</h4>
<p>how do you practically enforce that?</p>



<a name="203946791"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/203946791" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#203946791">(Jul 15 2020 at 12:12)</a>:</h4>
<p>trait implemented for valid <code>fn</code> pointers?</p>



<a name="203946837"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/203946837" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#203946837">(Jul 15 2020 at 12:12)</a>:</h4>
<p>oh and you can't have a <code>const fn</code> method to do the actual cast, I see :(</p>



<a name="203948743"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/203948743" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#203948743">(Jul 15 2020 at 12:32)</a>:</h4>
<p><span class="user-mention" data-user-id="257758">@Connor Horman</span> so close <a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=c5336a6215a47b1258011677bbead054">https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=c5336a6215a47b1258011677bbead054</a></p>



<a name="203948772"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/203948772" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#203948772">(Jul 15 2020 at 12:32)</a>:</h4>
<p>this is the good 'ol "create a ZST out of thin air" trick</p>



<a name="203948841"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/203948841" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#203948841">(Jul 15 2020 at 12:33)</a>:</h4>
<p>AFAIK without a <code>const fn</code> with a trait bound, or <code>typeof(function_name)</code> (which we don't have), there's no way to access an associated <code>const</code> on a function definition type</p>



<a name="203948918"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/203948918" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#203948918">(Jul 15 2020 at 12:34)</a>:</h4>
<p>the upshot of this approach is that you can use closures and it will still work correctly lol</p>



<a name="203948939"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/203948939" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#203948939">(Jul 15 2020 at 12:34)</a>:</h4>
<p>I have a working version, but it is at best, a hack. I need to carry arround the number of parameters.</p>



<a name="203948947"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/203948947" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#203948947">(Jul 15 2020 at 12:34)</a>:</h4>
<p>as the <code>extern "C" fn wrapper</code> handles all of the ABI</p>



<a name="203948960"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/203948960" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#203948960">(Jul 15 2020 at 12:34)</a>:</h4>
<p><span class="user-mention" data-user-id="257758">@Connor Horman</span> "carry around" like in a macro?</p>



<a name="203948967"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/203948967" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#203948967">(Jul 15 2020 at 12:34)</a>:</h4>
<p>Yeah</p>



<a name="203948994"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/203948994" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#203948994">(Jul 15 2020 at 12:35)</a>:</h4>
<p>that sounds like it avoids most of the complexity with my approach, yeah</p>



<a name="203949141"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/203949141" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#203949141">(Jul 15 2020 at 12:36)</a>:</h4>
<p><span class="user-mention" data-user-id="257758">@Connor Horman</span> wait, is your equivalent of my <code>ErasedFn</code> created at compile-time, or runtime?</p>



<a name="203949161"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/203949161" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#203949161">(Jul 15 2020 at 12:36)</a>:</h4>
<p>for some reason I thought you'd have a static array but maybe I was imagining that</p>



<a name="203949203"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/203949203" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#203949203">(Jul 15 2020 at 12:36)</a>:</h4>
<p>Which is incredibly annoying, and materializing a fn type from the parameter count is even more dirty hacks.<br>
Also, its compile-time, in an array w/ no_mangle</p>



<a name="203949225"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/203949225" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#203949225">(Jul 15 2020 at 12:37)</a>:</h4>
<p>ah so you do hit the restrictions I assumed</p>



<a name="203949291"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/203949291" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#203949291">(Jul 15 2020 at 12:37)</a>:</h4>
<p><span class="user-mention" data-user-id="257758">@Connor Horman</span> would it be enough if we had <code>as fn(..) -&gt; _</code> which inferred the arity?</p>



<a name="203949350"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/203949350" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#203949350">(Jul 15 2020 at 12:38)</a>:</h4>
<p>although that's a bit too close to <code>fn(...)</code> for comfort, which is a C variadic  :P</p>



<a name="203949470"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/203949470" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#203949470">(Jul 15 2020 at 12:39)</a>:</h4>
<p>Possibly, though these coercions would be nicer, as its honestly an ergonomics problem that I can't use the name of a function as a generic parameter with a trait bound implemented on the corresponding fn-pointer type</p>



<a name="203949601"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/203949601" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#203949601">(Jul 15 2020 at 12:40)</a>:</h4>
<p><span class="user-mention silent" data-user-id="119009">eddyb</span> <a href="#narrow/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer/near/203949291">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="257758">Connor Horman</span> would it be enough if we had <code>as fn(..) -&gt; _</code> which inferred the arity?</p>
</blockquote>
<p>Something similar for closures is proposed in <a href="https://github.com/rust-lang/rfcs/pull/2956">https://github.com/rust-lang/rfcs/pull/2956</a></p>



<a name="203949639"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/203949639" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#203949639">(Jul 15 2020 at 12:41)</a>:</h4>
<p>Variadic Generics would also solve the problem, though I'd expect its further off than anything to do with this.</p>



<a name="203949750"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/203949750" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#203949750">(Jul 15 2020 at 12:42)</a>:</h4>
<p><a href="https://github.com/LightningCreations/lcnix/blob/master/kernel/common/src/syscall.rs">https://github.com/LightningCreations/lcnix/blob/master/kernel/common/src/syscall.rs</a> is the specific use case.</p>



<a name="203950185"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/203950185" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#203950185">(Jul 15 2020 at 12:47)</a>:</h4>
<p>yeah I'm specifically talking about avoiding a dependency on VG</p>



<a name="203950246"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/203950246" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#203950246">(Jul 15 2020 at 12:47)</a>:</h4>
<p><span class="user-mention" data-user-id="116155">@Jake Goulding</span> that one is easier, assuming it doesn't do inference and just relies on the same thing that deduces <code>for&lt;...&gt;</code> lifetime parameterization for closures</p>



<a name="203950352"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/203950352" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#203950352">(Jul 15 2020 at 12:48)</a>:</h4>
<p>heh I found the relevant part in the RFC text, nice</p>



<a name="203950489"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/203950489" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#203950489">(Jul 15 2020 at 12:50)</a>:</h4>
<p><span class="user-mention" data-user-id="119009">@eddyb</span> I've no useful input on easiness or implementation or any of that. My main distaste with that RFC is that you can't do something similar with functions, but your proposal combined with the RFC at least makes the two the smallest bit more similar.</p>



<a name="203950517"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/203950517" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#203950517">(Jul 15 2020 at 12:50)</a>:</h4>
<p>you can already not do <em>many</em> things with functions like you can with closures</p>



<a name="203950523"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/203950523" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#203950523">(Jul 15 2020 at 12:50)</a>:</h4>
<p>I am aware.</p>



<a name="203950537"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/203950537" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#203950537">(Jul 15 2020 at 12:50)</a>:</h4>
<p>this is just one more thing that would require a much heavier extension (VG) at the function level</p>



<a name="203950563"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/203950563" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#203950563">(Jul 15 2020 at 12:51)</a>:</h4>
<p>I apologize for interrupting your discussion. I will endeavor to do it less in the future.</p>



<a name="203950581"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/203950581" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#203950581">(Jul 15 2020 at 12:51)</a>:</h4>
<p>lol no this is great</p>



<a name="203950597"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/203950597" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#203950597">(Jul 15 2020 at 12:51)</a>:</h4>
<p>I'm leaving a comment on the RFC showing my support for it</p>



<a name="203950628"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/203950628" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#203950628">(Jul 15 2020 at 12:51)</a>:</h4>
<p>it's just sadly less easy to do the <code>as fn(..) -&gt; _</code> thing because unlike closures, it has to be represented in the typesystem</p>



<a name="203950677"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/203950677" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#203950677">(Jul 15 2020 at 12:52)</a>:</h4>
<p>(or we can cheat, which is closer to closures)</p>



<a name="203951091"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/More%20coercions%20from%20fn%20item%20-%3E%20fn%20pointer/near/203951091" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/More.20coercions.20from.20fn.20item.20-.3E.20fn.20pointer.html#203951091">(Jul 15 2020 at 12:56)</a>:</h4>
<p><span class="user-mention" data-user-id="116155">@Jake Goulding</span> <a href="https://github.com/rust-lang/rfcs/pull/2956#discussion_r455028565">https://github.com/rust-lang/rfcs/pull/2956#discussion_r455028565</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>